package qijin

func DealData(ok bool, v interface{}, cnt ...int64) interface{} {
	m := map[string]interface{}{
		"code": "FAIL",
		"msg":  "",
		"data": "",
	}
	switch val := v.(type) {
	case error:
		if val != nil {
			m["msg"] = val.Error()
		}
	default:
		if ok {
			m["code"] = "SUCCESS"
			m["data"] = v
			if len(cnt) > 0 {
				m["count"] = cnt[0]
			}
		} else if v != nil {
			m["msg"] = v
		}
	}
	return m
}
